package com.itboye.jigongbao.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;

/**
 * Created by Administrator on 2017/12/22.
 */

public class ByTimeUtils {
    public static String timeFormat(String pattern, long time) {
        return new SimpleDateFormat(pattern).format(time);
    }

    public static long timeParse(String pattern, String time) {
        long times = 0;
        try {
            times = new SimpleDateFormat(pattern).parse(time).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return times;
    }

    public static String timeFormat(String inPattern, String outPattern, String inTime) {
        long times = 0;
        try {
            times = new SimpleDateFormat(inPattern).parse(inTime).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return new SimpleDateFormat(outPattern).format(times);
    }

    public static ArrayList<String> getDays(int year, int month) {
        ArrayList<String> ar = new ArrayList<>();
        switch (month) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                ar = arDays(31);
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                ar = arDays(30);
                break;
            case 2:
                if ((year % 4 == 0 && year % 100 != 0)
                        || (year % 4 == 0 && year % 100 == 0)) {
                    ar = arDays(29);
                    System.out.println(year + "年是闰年");
                } else {
                    ar = arDays(28);
                    System.out.println(year + "年是平年");
                }
                break;
        }
        return ar;
    }

    private static ArrayList<String> arDays(int num) {
        ArrayList<String> ar = new ArrayList<>();
        for (int i = 0; i < num; i++) {
            if (i + 1 < 10) {
                ar.add("0" + (i + 1) + "");
            } else {
                ar.add((i + 1) + "");
            }
        }
        ar.add(0, "全部");
        return ar;
    }
}
